package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.HrRoleAddDTO;
import org.jsola.hr.dto.HrRoleUpdateDTO;
import org.jsola.hr.entity.HrRoleDO;
import org.jsola.hr.query.HrRoleQuery;
import org.jsola.hr.service.IHrRoleService;
import org.jsola.hr.vo.HrRoleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;


/**
 * 人力角色表
 *
 * @author zhr
 */
@Component
public class HrRoleTestHelper extends BaseTestHelper {

    @Autowired
    private IHrRoleService hrRoleService;

    /**
     * 生成add测试数据
     *
     * @return HrRoleAddDTO
     */
    public HrRoleAddDTO getHrRoleAddDTO() {
        HrRoleAddDTO hrRoleAddDTO = new HrRoleAddDTO();
        hrRoleAddDTO.setName(getRandomValue("varchar",50));
        hrRoleAddDTO.setRoleIds(getRandomValue("text",2147483647));
        hrRoleAddDTO.setDescription(getRandomValue("varchar",500));
        hrRoleAddDTO.setCode(getRandomValue("varchar",50));
        hrRoleAddDTO.setReserveFlag(SafeKit.getBoolean(getRandomValue("tinyint",50)));
        return hrRoleAddDTO;
    }


    /**
     * 生成update测试数据
     *
     * @return HrRoleUpdateDTO
     */
    public HrRoleUpdateDTO getHrRoleUpdateDTO(HrRoleVO hrRoleVO) {
        return hrRoleService.selectDOById(hrRoleVO.getId(), SITE_ID).to(HrRoleUpdateDTO.class);
    }

    /**
     * 生成查询数据
     *
     * @return HrRoleQuery
     */
    public HrRoleQuery getHrRoleQuery() {
        HrRoleQuery hrRoleQuery = new HrRoleQuery();
        List<HrRoleDO> hrRoleDOList = hrRoleService.list(new HrRoleDO(), SITE_ID);
        if (!CollectionUtils.isEmpty(hrRoleDOList)) {
            HrRoleDO hrRoleDO = hrRoleDOList.get(0);
            hrRoleQuery = hrRoleDO.to(HrRoleQuery.class);
        }
        return hrRoleQuery;
    }

    /**
     * 保存示例
     *
     * @return HrRoleVO
     */
    public HrRoleVO saveHrRoleExample() {
        HrRoleAddDTO addDTO = this.getHrRoleAddDTO();
        return hrRoleService.save(addDTO, buildTokenUser());
    }


}

